import storage from '@/utils/storage';

// 全局权限指令  权限不足会删除元素
const auth = {
  mounted(el, binding, vnode) {
    // 获取用户权限
    const actionList = storage.getItem('actionList', []);
    // 获取绑定的值
    let value = binding.value;
    // 判断是否有权限
    let hasAuth = actionList.includes(value);
    if (!hasAuth) {
      el.style.display = 'none';
      el.parentNode.removeChild(el);
    }
  },
};

auth.install = function (app) {
  //定义指令名
  app.directive('auth', auth);
};

export default auth;
